import { get, post, put, del } from '@/utils/request';
import { 
  Role, 
  CreateRoleRequest, 
  UpdateRoleRequest, 
  PaginatedResponse,
  Permission 
} from './types';

// 角色管理相关 API
export const rolesApi = {
  // 获取角色列表
  getRoles: (params?: {
    page?: number;
    pageSize?: number;
    name?: string;
  }) => get('/roles', params),

  // 获取单个角色
  getRole: (id: number) => get(`/roles/${id}`),

  // 创建角色
  createRole: (data: CreateRoleRequest) => post('/roles', data),

  // 更新角色
  updateRole: (id: number, data: UpdateRoleRequest) => put(`/roles/${id}`, data),

  // 删除角色
  deleteRole: (id: number) => del(`/roles/${id}`),

  // 批量删除角色
  batchDelete: (ids: number[]) => del('/roles', { data: { ids } }),

  // 设置角色权限
  setPermissions: (id: number, permissions: Permission[]) => put(`/roles/${id}/permissions`, { permissions }),

  // 获取角色统计
  getStats: () => get('/roles/stats/overview'),

  // 获取所有角色
  getAllRoles: () => get('/roles/options/all'),

  // 获取可用权限
  getAvailablePermissions: () => get('/roles/permissions/available'),

  // 获取权限列表
  getPermissions: () => get('/roles/permissions/list'),

  // 分配菜单/按钮权限
  setMenus: (id: number, menuIds: number[]) => put(`/roles/${id}/menus`, { menuIds }),

  // 获取角色已分配菜单/按钮ID
  getMenus: (id: number) => get(`/roles/${id}/menus`),
}; 